package com.xm.dao.impl;

import com.xm.dao.BrandDao;
import com.xm.po.Brand;
import com.xm.util.BaseDao;
import com.xm.util.DButil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;

/**
 * @author Administrator
 * @date 2020-08-07-15:03
 * @description 品牌数据操作接口实现类
 */
public class BrandDaoImpl implements BrandDao {
    /**
     * 品牌列表
     * @return
     */
    @Override
    public List<Brand> getAll() {
        List<Brand>list= (List<Brand>) BaseDao.queryAll(Brand.class);
        return list;
    }

    @Override
    public boolean add(Brand brand) {
        return false;
    }

    @Override
    public boolean update(Brand brand) {
        return DButil.update(brand);
    }
    /**
     * 根据编号进行查询
     * @param id
     * @return
     */
    @Override
    public Brand findById(Integer id) {
        return (Brand) DButil.queryOne(Brand.class,id);
    }
    /**
     * 根据编号进行删除
     * @param id
     * @return
     */
    @Override
    public boolean deleteById(Integer id) {
        Connection conn = DButil.getConnection();
        PreparedStatement pstmt=null;
        String sql="delete from Brand where brandId=?";
        try {
            pstmt=conn.prepareStatement(sql);
            pstmt.setObject(1,id);
            return pstmt.executeUpdate()>0;
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            DButil.close(null,pstmt,conn);
        }
        return false;
    }
}
